package com.baili.controller.planner;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baili.dto.BaseTransferEntity;
import com.baili.dto.ProductOrder;
import com.baili.dto.SelectUserInput;
import com.baili.service.planner.PlannerService;
import com.baili.service.user.UserService;
import com.baili.util.MobileConfig;
import com.baili.util.StringUtil;

/** 
 * @author iceX
 * @version 创建时间：2016年3月30日 下午2:19:29 
 * @Name: PlannerController.java检验人员
 */
@Controller
@RequestMapping(value = "")
public class PlannerController {
	
	private static Logger log = Logger.getLogger(PlannerController.class);
	@Autowired
	private PlannerService plannerService;
	
	@Autowired
	private UserService userService;
	
	/**
	 * 计划人员-生产通知单-轮次状态查询(半成品)
	 * @param request
	 * @param response
	 * @return
	 */ 
	@RequestMapping(value = "/service/getProductOrderByRoundType")
	@ResponseBody
	public BaseTransferEntity getProductOrderByRoundType(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			
			List<Map<String,Object>> lst = new ArrayList<Map<String,Object>>();
			
			ProductOrder productOrder = new ProductOrder();
			
			String planner = request.getParameter("planner");
			
			String roundType = request.getParameter("roundType");
			
			String processId = request.getParameter("processId");
			
			String scheduleNo = request.getParameter("scheduleNo");
			String userId = request.getParameter("userId");
			
			//TODO 添加参数 checkRound  未制定checkRound为0  已制定为1或2 被驳回为3
			
			productOrder.setId(Integer.parseInt(processId));
			
			productOrder.setScheduleNo(scheduleNo);
			
			List<Map<String,Object>> processNameLst = userService.getProcessNameByUser(Integer.parseInt(userId));
			
			Map<String, Object> processNameMap = processNameLst.get(0);
			
			productOrder.setProcessName(processNameMap.get("processName").toString());
			
			//System.out.println(processName);
			if(Integer.parseInt(planner) == 1){//(1：为半成品)
				
				if(roundType.equals("0")){
					
					if(productOrder.getProcessName().equals("开料")){
						
						productOrder.setProcessName("帮面");
						
						productOrder.setKzType(0);
					}else if(productOrder.getProcessName().equals("制帮")){
						
						productOrder.setProcessName("帮面");
						
						productOrder.setKzType(0);
					}
					
					productOrder.setRoundType(Integer.parseInt(roundType));
					
					lst = plannerService.getProductOrderByRoundTypeP(productOrder);
				}else{
					
					if(productOrder.getProcessName().equals("开料")){
						
						productOrder.setProcessName("帮面");
						
					}else if(productOrder.getProcessName().equals("制帮")){
						
						productOrder.setProcessName("帮面");
						
						productOrder.setKzType(0);
					}
					
					productOrder.setRoundType(Integer.parseInt(roundType));
					
					lst = plannerService.getProductOrderByRoundTypePSee(productOrder);
				}
				
			}else if(Integer.parseInt(planner) == 2){//(2：为成品)
				if(roundType.equals("0") || roundType.equals("3")){
					
					if(productOrder.getProcessName().equals("前段")){
						
						productOrder.setStage(0);
					}
					
					productOrder.setRoundType(Integer.parseInt(roundType));
					//获取列表数据(成品)
					lst = plannerService.getProductOrderByRoundTypeF(productOrder);
				}else{
					
					productOrder.setRoundType(Integer.parseInt(roundType));
					//获取列表数据(成品)
					lst = plannerService.getProductOrderByRoundTypeFSee(productOrder);
				}
			}
			
			for( Map<String, Object> map : lst){
				
				map.put("processName", productOrder.getProcessName());
				
			}
			
			//返回列表数据
			if(lst == null || lst.size() < 1){
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.success"));
				baseTransferEntity.setData(lst);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.success"));
			
		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}
			
		
		return baseTransferEntity;
	}
	
	/**
	 * 计划人员人员-生产通知单-根据产品代码处理轮次(查看)
	 * @param request
	 * @param response
	 * @return
	 */ 
	@RequestMapping(value = "/service/handleProductOrderByProductCode")
	@ResponseBody
	public BaseTransferEntity handleProductOrderByProductCode(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			List lst = new ArrayList();
			ProductOrder productOrder = new ProductOrder();
			String productCode = request.getParameter("productCode");
			String scheduleNo = request.getParameter("scheduleNo");
			String planner = request.getParameter("planner");
			
			productOrder.setProductCode(productCode);
			
			productOrder.setScheduleNo(scheduleNo);
			
			productOrder.setPlanner(planner);
			//获取列表数据
			lst = plannerService.handleProductOrderByProductCode(productOrder);
			
			//返回列表数据
			if(lst == null || lst.size() < 1){
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.success"));
				baseTransferEntity.setData(lst);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.success"));
			
		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}
			
		
		return baseTransferEntity;
	}
	/**
	 * 计划人员人员-生产通知单-根据产品代码处理轮次(查看)
	 * @param request
	 * @param response
	 * @return
	 */ 
	@RequestMapping(value = "/service/handleProductOrderByProductCodeSchedule")
	@ResponseBody
	public BaseTransferEntity handleProductOrderByProductCodeSchedule(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			List lst = new ArrayList();
			ProductOrder productOrder = new ProductOrder();
			String productCode = request.getParameter("productCode");
			String scheduleNo = request.getParameter("scheduleNo");
			String planner = request.getParameter("planner");
			
			productOrder.setProductCode(productCode);
			
			productOrder.setScheduleNo(scheduleNo);
			
			productOrder.setPlanner(planner);
			//获取列表数据
			lst = plannerService.handleProductOrderByProductCodeSchedule(productOrder);
			
			//返回列表数据
			if(lst == null || lst.size() < 1){
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig.getString("msg.global.success"));
			
		} catch (Exception e) {
			log.error("handleProductOrderByProductCodeSchedule --------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}
		
		return baseTransferEntity;
	}
	
	/**
	 * 计划人员人员-生产通知单-根据产品代码处理轮次(查看bom)
	 * @param request
	 * @param response
	 * @return
	 */ 
	@RequestMapping(value = "/service/getBomList")
	@ResponseBody
	public BaseTransferEntity getBomList(HttpServletRequest request,
			HttpServletResponse response) {
		
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		
		try {
			
			String productCode = request.getParameter("productCode");
			
			String scheduleNo = request.getParameter("scheduleNo");
			
			List<Map<String,Object>> lst = new ArrayList<Map<String,Object>>();
			
			ProductOrder productOrder = new ProductOrder();
			
			productOrder.setProductCode(productCode);
			
			productOrder.setScheduleNo(scheduleNo);
				
			//获取列表数据
			lst = plannerService.getBomList(productOrder);
			
			//返回列表数据
			if(lst == null || lst.size() < 1){
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.success"));
				baseTransferEntity.setData(lst);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.success"));
			
		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}
			
		
		return baseTransferEntity;
	}
	
	/**
	 * 计划人员人员-生产通知单-根据产品代码处理轮次(查看定额领料单)
	 * @param request
	 * @param response
	 * @return
	 */ 
	@RequestMapping(value = "/service/getNormedList")
	@ResponseBody
	public BaseTransferEntity getNormedList(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			
			String productCode = request.getParameter("productCode");
			
			String scheduleNo = request.getParameter("scheduleNo");
			
			List<Map<String,Object>> lst = new ArrayList<Map<String,Object>>();
			
			ProductOrder productOrder = new ProductOrder();
			
			productOrder.setProductCode(productCode);
			
			productOrder.setScheduleNo(scheduleNo);
			
			// String planner = request.getParameter("planner");
			
			//获取列表数据
			lst = plannerService.getNormedList(productOrder);
			
			//返回列表数据
			if(lst == null || lst.size() < 1){
				
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig.getString("msg.global.success"));
			
		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}
		
		
		return baseTransferEntity;
	}
	
	/**
	 * 预警
	 * @param request
	 * @param response
	 * @return
	 */ 
	@RequestMapping(value = "/service/warning")
	@ResponseBody
	public BaseTransferEntity warning(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			//String productCode = request.getParameter("productCode");
			List<Map<String, Object>> warning = new ArrayList<Map<String,Object>>();
			
			List<Map<String,Object>> lst = new ArrayList<Map<String,Object>>();
 			ProductOrder productOrder = new ProductOrder();
			
			String planner = request.getParameter("planner");
			
			String processId = request.getParameter("processId");
			
			productOrder.setId(Integer.parseInt(processId));
			
			String userId = request.getParameter("userId");
			
			String scheduleNo = request.getParameter("scheduleNo");
			
			List<Map<String,Object>> processNameLst = userService.getProcessNameByUser(Integer.parseInt(userId));
			
			productOrder.setId(Integer.parseInt(userId));
			
			productOrder.setScheduleNo(scheduleNo);
			
			if(Integer.parseInt(planner) == 1){//(1：为半成品)
				
				productOrder.setRoundType(0);
				
				Map<String, Object> processNameMap = processNameLst.get(0);
				
				productOrder.setProcessName(processNameMap.get("processName").toString());
				
				if(productOrder.getProcessName().equals("开料")){
					
					productOrder.setProcessName("帮面");
					
				}else if(productOrder.getProcessName().equals("制帮")){
					
					productOrder.setProcessName("帮面");
					
				}
				
				//获取列表数据(半成品)
				warning = plannerService.getProductOrderByRoundTypeP(productOrder);
				
			}else if(Integer.parseInt(planner) == 2){//(2：为成品)
				
				productOrder.setRoundType(0);
				//获取列表数据(成品)
				warning = plannerService.getProductOrderByRoundTypeF(productOrder);
				
			}
			
			for (Map<String, Object> map : warning) {
				
				Date overTime = sdf.parse(map.get("overTime").toString());
				
				long date1=overTime.getTime();
				
				long date2=(new Date()).getTime();

				long timeDifference = (date2-date1);
				
				double days = ((double)timeDifference/(24*60*60*1000));
				
				int returnDay = (int)Math.ceil(days)-1;
				
				if(days<0){
					
					if(days >-1){
						
						returnDay = -1000000;
						
					}
					
				}else if(days>=0){
					
					if(days < 1){
						
						returnDay = 1000000;
						
					}
				}
				
				map.put("warningRank", returnDay);
				
				map.put("processName", productOrder.getProcessName());
				
			}
			
			//返回列表数据
			if(warning == null || warning.size() < 1){
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.success"));
			baseTransferEntity.setData(warning);
			baseTransferEntity.setDesc(MobileConfig.getString("msg.global.success"));
			
		} catch (Exception e) {
			log.error("--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}
		
		return baseTransferEntity;
	}
	
	/**
	 * 统计分析-列表
	 * @param request
	 * @param response
	 * @return
	 */ 
	@RequestMapping(value = "/service/getListByOvertimeType")
	@ResponseBody
	public BaseTransferEntity getListByOvertimeType(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			
			List<Map<String,Object>> lst = new ArrayList<Map<String,Object>>();
			
			int planner = Integer.parseInt(request.getParameter("planner"));
			
			String processId = request.getParameter("processId");
			
			String startTime = request.getParameter("startTime");
			
			String overTime = request.getParameter("overTime");
			
			String userId = request.getParameter("userId");

			ProductOrder productOrder = new ProductOrder();
			
			productOrder.setId(Integer.parseInt(processId));
			
			List<Map<String,Object>> processNameLst = userService.getProcessNameByUser(Integer.parseInt(userId));
			
			Map<String, Object> processMap = processNameLst.get(0);
			
//			if(StringUtil.isEmpty(startTime) && StringUtil.isEmpty(overTime)){
//				
//				startTime = sdf.format(StringUtil.MinusDay(new Date(), 7));
//				
//				overTime = sdf.format(new Date());
//			}
			
			productOrder.setStartTime(startTime);
			
			if(!StringUtil.isEmpty(overTime)){
				
				Date overTimeDate = StringUtil.parseDate2(overTime, "yyyy-MM-dd");
				
				Date overTimeDateAdd = StringUtil.addDay(overTimeDate, 1);
				
				productOrder.setOverTime(StringUtil.date2String(overTimeDateAdd));
				
			}
			
//			productOrder.setOverTime(overTime);
			
			productOrder.setProcessName(processMap.get("processName").toString());
			
			if(planner==1){
				if(productOrder.getProcessName().equals("开料")){
					
					productOrder.setProcessName("帮面");
					
				}else if(productOrder.getProcessName().equals("制帮")){
					
					productOrder.setProcessName("帮面");
					
				}
				//获取列表数据
				lst = plannerService.getListByOvertimeTypeP(productOrder);	
			}else if(planner==2){
				//获取列表数据
				lst = plannerService.getListByOvertimeTypeF(productOrder);
			}
			//返回列表数据
			if(lst == null || lst.size() < 1){
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.success"));
				baseTransferEntity.setData(lst);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.success"));
			
		} catch (Exception e) {
			log.error("warningList 呼叫主题--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}
		return baseTransferEntity;
	}
	/**
	 * 半成品计划人员--根据时间统计分析
	 * @param request
	 * @param response
	 * @return
	 */ 
	@RequestMapping(value = "/service/getTimeTypeListByTime")
	@ResponseBody
	public BaseTransferEntity getTimeTypeListByTime(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			String startTime = request.getParameter("startTime");
			String overTime = request.getParameter("overTime");
			Map<String,Object> map = new HashMap<String, Object>();
			int planner = Integer.parseInt(request.getParameter("planner"));

			if(StringUtil.isEmpty(startTime) && StringUtil.isEmpty(overTime)){
				
				startTime = sdf.format(StringUtil.MinusDay(new Date(), 7));
				
				overTime = sdf.format(new Date());
			}
			
			Date overTimeDateAdd = null;
			
			if(!StringUtil.isEmpty(overTime)){
				
				Date overTimeDate = StringUtil.parseDate2(overTime, "yyyy-MM-dd");
				
				overTimeDateAdd = StringUtil.addDay(overTimeDate, 1);
			}
			
			if(planner==1){
				//获取列表数据
				map = plannerService.getTimeTypeListByTime(startTime,StringUtil.date2String(overTimeDateAdd));	
			}else if(planner==2){
				//获取列表数据
				map = plannerService.getTimeTypeListByTime(startTime,StringUtil.date2String(overTimeDateAdd));
			}
			//返回列表数据
			if(map == null || map.size() < 1){
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
				baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.success"));
				baseTransferEntity.setData(map);
				baseTransferEntity.setDesc(MobileConfig.getString("msg.global.success"));
			
		} catch (Exception e) {
			log.error("getTimeTypeListByTimes 呼叫主题--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}
		return baseTransferEntity;
	}
	
	/**
	 * 轮次制定(更新生产小组字段，更新轮次审核字段，以产品编码为条件对生产通知单表进行更新)
	 * @param request
	 * @param response
	 * @return
	 */ 
	@RequestMapping(value = "/service/updateProductOrderPTeam")
	@ResponseBody
	public BaseTransferEntity updateProductOrderPTeam(HttpServletRequest request,
			HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			
			String productTeamId = request.getParameter("productTeamId");
			
			String productCode = request.getParameter("productCode");
			
			String userId = request.getParameter("userId");
			
			String scheduleNo = request.getParameter("scheduleNo");
			
			String processId = request.getParameter("processId");
			
			String apprUserId = request.getParameter("apprUserId");
			
			String operatorId = request.getParameter("operatorId");
			
			ProductOrder productOrder = new ProductOrder();
			
			productOrder.setId(Integer.parseInt(processId));
			
			productOrder.setApprUserId(Integer.parseInt(apprUserId));
			
			List<Map<String,Object>> processNameLst = userService.getProcessNameByUser(Integer.parseInt(userId));

			Map<String, Object> map = processNameLst.get(0);

			String processName = map.get("processName").toString();

			if(processName.equals("中底") || processName.equals("成型底")|| processName.equals("前段")){
				
				productOrder.setOperatorId(Integer.parseInt(operatorId));
				
			}
			
			
			int stage = 0;
			
			int kzType = 0;

			if (processName.equals("开料") || processName.equals("制帮")) {

				kzType = 1;

			} else if (processName.equals("前段")) {

				stage = 1;

			} 
			
			productOrder.setCheckRound(1);
			//roundType应删除    同时   plannerMapper.xml文件下的 updateProductOrderPTeam语句中的,roundType = #{roundType}应被删除   
			//该属性应在公司领导模块的审批处设置，该字段初始值为0，若审批通过则将该值设为1，若审批被驳回，则将该字段设为2
			//同理，在公司领导处，我们只关心该轮次是待审核状态还是审核通过状态即可。
			productOrder.setRoundType(1);
			
			productOrder.setStage(stage);
			
			productOrder.setKzType(kzType);
			
			productOrder.setProductTeamId(Integer.parseInt(productTeamId));
			
			productOrder.setProductCode(productCode);
			
			productOrder.setUserId(Integer.parseInt(userId));
			
			productOrder.setScheduleNo(scheduleNo);
			
			plannerService.updateProductOrderPTeam(productOrder);
			
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData("");
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));
			
		} catch (Exception e) {
			log.error("updateProductOrderPTeam 轮次制定(更新生产小组字段，更新轮次审核字段，以产品编码为条件对生产通知单表进行更新)--------->" + e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}
		return baseTransferEntity;
	}
	
	/**
	 * 轮次制定(更新生产小组字段，更新轮次审核字段，以产品编码为条件对生产通知单表进行更新)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getApprovalList")
	@ResponseBody
	public BaseTransferEntity getApprovalList(
			HttpServletRequest request, HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			String productCode = request.getParameter("productCode");

			ProductOrder productOrder = new ProductOrder();

			productOrder.setProductCode(productCode);

			// 获取列表数据
			List lst = plannerService
					.getApprovalList(productOrder);
			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				//baseTransferEntity.setTotalCount("");
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			//baseTransferEntity.setTotalCount("");
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));

		} catch (Exception e) {
			log.error(
					"queryProductionOrderApprovalList --------->"
							+ e.getMessage(), e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}
	
	/**
	 * 轮次制定(更新生产小组字段，更新轮次审核字段，以产品编码为条件对生产通知单表进行更新)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getProductionOrderParam")
	@ResponseBody
	public BaseTransferEntity getProductionOrderParam(
			HttpServletRequest request, HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {

			String productCode = request.getParameter("productCode");
			int productTeamId = Integer.parseInt(request
					.getParameter("productTeamId"));

			ProductOrder productOrder = new ProductOrder();

			productOrder.setProductCode(productCode);
			productOrder.setProductTeamId(productTeamId);
			// 获取列表数据
			List lst = plannerService
					.getProductionOrderParam(productOrder);
			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));
		} catch (Exception e) {
			log.error(
					"queryProductionOrderParameter --------->" + e.getMessage(),
					e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}
	
	/**
	 * 轮次制定(更新生产小组字段，更新轮次审核字段，以产品编码为条件对生产通知单表进行更新)
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getProductTeam")
	@ResponseBody
	public BaseTransferEntity getProductTeam(
			HttpServletRequest request, HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {

			String processId = request.getParameter("processId");

			ProductOrder productOrder = new ProductOrder();

			productOrder.setId(Integer.parseInt(processId));
			
			List lst = new ArrayList();
			
			Map map = new HashMap();
			
			map.put("productTeam", plannerService.getProductTeam(productOrder));
			
			// 获取列表数据
			SelectUserInput selectUserInput = new SelectUserInput();
			
			selectUserInput.setRoleType("L");
			
			map.put("userByRole", userService.getUserByRoleType(selectUserInput));
			
			lst.add(map);
			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));
		} catch (Exception e) {
			log.error(
					"queryProductionOrderParameter --------->" + e.getMessage(),
					e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}
	
	/**
	 * 查询数据库内设定的size
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getBLSize")
	@ResponseBody
	public BaseTransferEntity getBLSize(
			HttpServletRequest request, HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			
			List lst =  plannerService.getBLSize();
			
			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));
		} catch (Exception e) {
			log.error(
					"queryProductionOrderParameter --------->" + e.getMessage(),
					e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}
	
	/**
	 * 查询数据库内设定的size
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/getSizeBySex")
	@ResponseBody
	public BaseTransferEntity getSizeBySex(
			HttpServletRequest request, HttpServletResponse response) {
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		try {
			
			String sex = request.getParameter("sex");
			
			List lst =  plannerService.getSizeBySex(Integer.parseInt(sex));
			
			// 返回列表数据
			if (lst == null || lst.size() < 1) {
				baseTransferEntity.setResultcode(MobileConfig
						.getStringCode("code.global.error.list"));
				baseTransferEntity.setData(null);
				baseTransferEntity.setDesc(MobileConfig
						.getString("msg.global.error.list"));
				return baseTransferEntity;
			}
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData(lst);
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));
		} catch (Exception e) {
			log.error(
					"queryProductionOrderParameter --------->" + e.getMessage(),
					e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}

		return baseTransferEntity;
	}
	
	/**
	 * 添加生产通知单
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/service/addProductOrder")
	@ResponseBody
	public BaseTransferEntity addProductOrder(
			HttpServletRequest request, HttpServletResponse response) {
		
		BaseTransferEntity baseTransferEntity = new BaseTransferEntity();
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		try {
			//排程号
			String scheduleNo = request.getParameter("scheduleNo");
			//成品产品代码
			String finishedProductCode = request.getParameter("finalizedProductCode");
			//成品产品名称
			String finishedProductName = request.getParameter("finalizedProductName");
			//帮面产品代码
			String upperProductCode = request.getParameter("upperProductCode");
			//帮面产品名称
			String upperProductName = request.getParameter("upperProductName");
			//中底产品代码
			String midsoleProductCode = request.getParameter("midsoleProductCode");
			//中底产品名称
			String midsoleProductName = request.getParameter("midsoleProductName");
			//成型底产品代码
			String outsoleProductCode = request.getParameter("outsoleProductCode");
			//成型底产品名称
			String outsoleProductName = request.getParameter("outsoleProductName");
			//鞋号和产品数量
			String sizeAndCount = request.getParameter("sizeAndCount");
			//生产车间
			String workShop = request.getParameter("workShop");
			//计划开工时间
			String startTime = request.getParameter("startTime");
			//计划完工时间
			String overTime = request.getParameter("overTime");
			//入库库区
			String inputArea = request.getParameter("inputArea");
			//款号
			String styleNo = request.getParameter("styleNo");
			//计划人员id(当前人员id)
			String userId = request.getParameter("userId");
			//使用当前人员id查询出当前登录人员所负责的工序名称
			List<Map<String,Object>> processNameLst = userService.getProcessNameByUser(Integer.parseInt(userId));
			
			String processName = "";
			//判断所获取到的工序名称是否为空(理论上不为空)
			if(processNameLst != null && processNameLst.size() > 0){
				
				processName = processNameLst.get(0).get("processName").toString();
			}
			//将鞋码和数量的串，解析
			String[] str = sizeAndCount.split(",");
			//循环
			for (int j = 0; j < str.length; j++) {

				String[] strs = str[j].split("-");

				ProductOrder productOrder = new ProductOrder();
				//添加排程号
				productOrder.setScheduleNo(scheduleNo);
				//添加产品代码
				productOrder.setProductCode(finishedProductCode);
				//添加产品名称
				productOrder.setProductName(finishedProductName);
				//添加鞋码
				productOrder.setSize(Integer.parseInt(strs[0]));
				//添加数量
				productOrder.setProductCount(Integer.parseInt(strs[1]));
				//添加生产车间
				productOrder.setWorkShop(workShop);
				//添加完工时间
				productOrder.setStartTime(startTime);
				
				productOrder.setOverTime(overTime);
				
				//productOrder.setOverTime(overTime);
				
				//添加入库库区
				productOrder.setInputArea(inputArea);
				//添加成品名称
				productOrder.setFinishedProductName(finishedProductName);
				//添加生产状态
				productOrder.setState(1);
				//添加实际开工时间(初始值设为1970-01-01 08:00:00，时间戳的值为0)
				productOrder.setRealStartTime("1970-01-01 08:00:00");
				//添加实际完工时间(初始值设为1970-01-01 08:00:00，时间戳的值为0)
				productOrder.setRealOverTime("1970-01-01 08:00:00");
				//添加产品款号
				productOrder.setStyleNo(styleNo);
				//以工序名称判断要如何设置各状态
				//if(processName.equals("开料") ||processName.equals("制帮")){
					//将生产通知单设置为开料(kzType为1时，即为开料工序)
				
					
				//}else if(processName.equals("前段") || processName.equals("中段") || processName.equals("后段")){
					//将生产通知单设置为前段(stage为1时，即为前段工序)
			    //}
				
				// 添加成品生产通知单
				productOrder.setStage(1);
				productOrder.setSerialNum(4);
				plannerService.addProductOrder(productOrder);
				
				productOrder.setStage(0);
				// 添加中底生产通知单
				productOrder.setProductCode(midsoleProductCode);
				productOrder.setProductName(midsoleProductName);
				productOrder.setSerialNum(2);
				
				plannerService.addProductOrder(productOrder);
				
				// 添加成型底生产通知单
				productOrder.setProductCode(outsoleProductCode);
				productOrder.setProductName(outsoleProductName);
				productOrder.setSerialNum(3);
				
				plannerService.addProductOrder(productOrder);
				// 添加帮面生产通知单
				productOrder.setKzType(1);
				productOrder.setProductCode(upperProductCode);
				productOrder.setProductName(upperProductName);
				productOrder.setSerialNum(1);
				
				plannerService.addProductOrder(productOrder);
				
			}
			//成功返回成功状态
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.success"));
			baseTransferEntity.setData("");
			baseTransferEntity.setDesc(MobileConfig
					.getString("msg.global.success"));
		} catch (Exception e) {
			log.error(
					"addProductOrder(添加生产通知单时出现异常): --------->" + e.getMessage(),
					e);
			baseTransferEntity.setResultcode(MobileConfig
					.getStringCode("code.global.error.exception"));
			baseTransferEntity.setDesc("系统接口异常，请联系管理员！");
			baseTransferEntity.setData("");
		}
		
		return baseTransferEntity;
	}
}
